#ifndef __Dictionary_H__
#define __Dictionary_H__

#include <vector>
#include <map>
#include <set>
#include <string>
#include "CandidateResult.h"
using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;

class Dictionary
{
    Dictionary();
    ~Dictionary();
public:
    static Dictionary* getInstance();
    static void destory();
public:
    vector<CandidateResult> doQuery(const string& key);
    void queryIndex();
    int distance(string candidate,string key);
    
    void readDict(const string& filename);
    void readIndex(const string& filename);
    void showDict() const ;
    void showIndex() const;

    int editDistance(const std::string &lhs, const std::string &rhs);
    int triple_min(const int &a, const int &b, const int &c);
    size_t nBytesCode(const char ch);
    std::size_t length(const std::string &str);
private:
    static Dictionary * _pInstance;
    map<string,int> _tmpDict;                   //辅助词典，用于加快查询速度
    vector<pair<string,int>> _dict;
    map<string,set<int>> _index;
};



#endif
